#include <stdio.h>
#include "ofc/DTrueTypeFont.h"

int main(int argc, char *argv[])
{
#ifdef HAVE_DTRUETYPEFONT 
  DTrueTypeFont *font = [DTrueTypeFont new];
  DFT_Glyph    glyph;

  unsigned     width,height;
  char         name[] = "../test/arial.ttf";

  if ([font open :name])               // Open font file
  {                                    // Print font info
    printf("Family name:%s\n",    [font familyName]);
    printf("Style name:%s\n",     [font styleName]);
    printf("Glyphs in font:%d\n", [font glyphsInFont]);

    [font size :"a" :20 :15];          // Give the glyphs a size

    [font stringSize :"hello" :&width :&height]; // Get string dimensions
    printf("String size of \"hello\":%u - %u\n", width, height);

    if ([font glyph :'a' :&glyph])     // Render a character to a glyph
    {
      unsigned xe = glyph.bitmapWidth -1;
      unsigned ye = glyph.bitmapHeight - 1;
      unsigned x,y;
      
      unsigned char *bitmap = glyph.bitmap;
     
      printf("Glyph bitmap:\n");       // Print the bitmap of the glyph
      for (y = 0; y <= ye; y++)
      {
        unsigned char  mask = 0x80;
        unsigned char *line = bitmap;
        
        for (x = 0; x <= xe; x++)
        {
          printf("%c", ((*line & mask) ? '1' : '0'));

          mask >>= 1;
          if (mask == 0)
          {
            mask = 0x80;
            line++;
          }
        }
        bitmap += glyph.bitmapPitch;
        printf("\n");
      }
    }
    else
      printf("The glyph 'a' is not present in the font.\n");

    [font close];
  }
  else
    printf("Could not open font file \"%s\".\n", name);

  [font free];
#else
  printf("DBigDouble is not present in the library.\n");
#endif
  return 0;
}

